package com.huanghuai.retail.entity;

import cn.hutool.core.util.StrUtil;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public enum BillTypeEnum {
    CG_PUT(1, "采购入库"),
    QT_PUT(2, "其他入库"),
    XSTH_PUT(3, "销售退货入库"),
    CGTH_PUT(4, "采购退货"),
    XS_OUT(5, "销售出库"),
    QT_OUT(6, "其他出库");
    //根据 ID 查 类型

    public static Integer getIdByName(String typeName) {
        if (StrUtil.isNotBlank(typeName))
            for (BillTypeEnum value : BillTypeEnum.values()) {
                if (value.typeName.equals(typeName)) {
                    return value.id;
                }
            }
        return null;
    }


    //根据 类型 查 ID
    public static String getNameById(Integer id) {
        if (id == null) {
            return null;
        }
        for (BillTypeEnum value : BillTypeEnum.values()) {
            if (value.id.equals(id)) {
                return value.typeName;
            }
        }
        return null;
    }

    //查询所有类型名称
    public static List<Map<String, String>> getAllType() {
        List<Map<String, String>> list = new ArrayList<>();
        for (BillTypeEnum value : BillTypeEnum.values()) {
            Map<String, String> map = new HashMap<>();
            map.put("typeName", value.typeName);
            list.add(map);
        }
        if (list.isEmpty()) {
            return null;
        }
        return list;
    }

    private final Integer id;
    private final String typeName;

    BillTypeEnum(Integer id, String typeName) {
        this.id = id;
        this.typeName = typeName;
        
    }
}
